package com.lesama.udp.chatroom;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Server {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(9999);
        while(true) {
            DatagramPacket packet = new DatagramPacket(new byte[1024], 1024);
            socket.receive(packet);
            byte[] data = packet.getData();
            InetAddress address = packet.getAddress();
            String s = new String(data, 0, packet.getLength());
            System.out.println("来自" + address + "发送了消息： " + s);
        }
    }
}
